package com.ics.atable.chat.config;

import com.alibaba.cloud.ai.memory.redis.RedissonRedisChatMemoryRepository;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ChatMemory配置
 *
 * @author haohongbin
 */
@Configuration
public class ChatMemoryConfiguration {

    private static final int MAX_MESSAGES = 10;
    private final RedissonRedisChatMemoryRepository redisChatMemoryRepository;

    public ChatMemoryConfiguration(RedissonRedisChatMemoryRepository redisChatMemoryRepository) {
        this.redisChatMemoryRepository = redisChatMemoryRepository;
    }

    @Bean
    public ChatMemory customChatMemory() {
        return MessageWindowChatMemory.builder()
                .chatMemoryRepository(redisChatMemoryRepository)
                .maxMessages(MAX_MESSAGES)
                .build();
    }
}
